﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WMS_Order_ShelveItem.aspx.cs" Inherits="JYH.Web.MES.WMS.UI.WMS_Order_ShelveItem" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script type="text/javascript">


        $(function () {
            const urlParams = new URLSearchParams(location.search);
            $("#hTradeOrderID").val(urlParams.get('params'));
        })

        function uploadFile() {
            const fileInput = document.getElementById('fileInput');
            const file = fileInput.files[0];
            if (!file) {
                Alert("请选择文件");
                return;
            }
            //multipart/form-data
            const formData = new FormData();
            formData.append("file", file);
            formData.append("TradeOrderID", $("#hTradeOrderID").val());

            var xhr = new XMLHttpRequest();
            xhr.open("POST", "/api/WMS/DBImport", true);
            // 设置上传完成后的回调
            xhr.onload = function () {
                if (xhr.status === 200) {
                    try {
                        var data = JSON.parse(xhr.responseText);
                        console.log(data);
                        if (data.Code === 200) {
                            CloseSubWindowAfterNotice("Success");
                        } else {
                            Alert("Error：" + (data.Message || "unknown"));
                        }
                    } catch (e) {
                        Alert("Error");
                    }
                } else {
                    Alert(JSON.parse(xhr.responseText));
                }
            };

            // 错误处理
            xhr.onerror = function () {
                Alert("Error");
            };

            // 发送请求
            xhr.send(formData);
        }
    </script>
</head>
<body>

    <form id="form1" runat="server">
        <asp:HiddenField runat="server" ID="hTradeOrderID" />
        <div class="pagebox">
            <!--工具栏-->
            <div class="easyui-panel" style="padding: 25px; width: 47%;">
                <ul class="flist">
                    <li>
                        <a href="../../../UploadFile/Execl/WmsTradeOrderInfo_DB.xlsx" class="easyui-linkbutton" data-options="iconCls:'icon-xiangmu1'">调拨来源明细EXECL模板下载</a>
                        <br />
                        <br />
                    </li>
                    <li>
                        <input type="file" id="fileInput" accept=".xlsx,.xls" style="color: red; width: 250px" />
                        <%--    <asp:FileUpload ID="FileUpload1" runat="server" Style="color: Red;" Width="250px" />--%>
                        <br />
                        <br />
                    </li>
                    <li>
                        <a href="javascript:;" class="easyui-linkbutton c4" onclick="uploadFile()" id="SaveItems" style="margin-left: 160px">导入</a>
                    </li>
                </ul>
            </div>
        </div>
    </form>
</body>
</html>
